<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/12/29
 * Time: 14:01
 */
namespace app\factory\controller;
class Upload extends Base
{
    /**
     * 文件上传至本地
     */
    public function upload(){
        $file = request()->file('file');
        $dir = ROOT_PATH . 'public' . DS . 'uploads/files';
        if(!file_exists($dir)){
            //检查是否有该文件夹，如果没有就创建，并给予最高权限
            mkdir($dir, 0700,true);
        }
        $info = $file->move($dir);
        if($info){
            $newName = str_replace ('\\','/',$info->getSaveName());
            echo "/uploads/files/{$newName}";
        }else{
            echo $file->getError();
        }
    }


    public function deleteLocality(){
        $add  = input('add');
        $add = substr ($add,1);
        if(unlink($add)){
            return json(['code'=>200,'msg'=>'删除成功！']);
        }else{
            return json(['code'=>100,'msg'=>'删除失败！']);
        }
    }
}